package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int     `gorm:"type:int(10);"`
	OrderSn     string  `gorm:"type:varchar(100);"`
	Num         int     `gorm:"type:int(10);"`
	Amount      float64 `gorm:"type:decimal(10,2);"`
	OrderType   int     `gorm:"type:tinyint;comment:1:支付宝;2:微信"`
	OrderStatus int     `gorm:"type:tinyint(1);comment:1:已支付;2:待支付;3:未支付;4:支付取消;5:支付失败"`
	Time        string  `gorm:"type:varchar(100);"`
	GoodsTitle  string  `gorm:"type:varchar(100);"`
	GoodsStock  int     `gorm:"type:int(10);"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2);"`
}

func (o *Order) Create() error {
	return DB.Create(&o).Error
}
func (o *Order) OrderList(orderStatus int64) (list []*Order, err error) {
	if orderStatus == 0 {
		err = DB.Find(&list).Error
	} else {
		err = DB.Where("order_status = ?", 1).First(&list).Error
	}
	return
}
